import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";

function getNewLogin(item) {
    return deleteDeptBind(item)
}

export default function deleteDeptBind(items) {
    //item為數組，元素的值是：userId_roleId
    console.log(items)
    let token = localStorage.getItem("token")

    let status = null
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
                'Authorization': token
        },
        url: url.api_url+`DeptBindRole/DelDept`,
        type: 'POST',
         contentType:"application/json",
         data: JSON.stringify({
             DEPT_ID_LIST:items
         }),
        success: function (result) {
            status = result.result;
            if(status=="Token過期請重新登錄") {
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(items)
            }else {
                if(status=="ok"){
                    message.success("删除成功");
                }else {
                    message.error("删除失败")
                }
            }
        },
        error:function (error) {
            status = "error";
            message.error("请求异常")
        }
    })
    return status;

//  写ajax时把上面注释取消
//     return 'ok';
}

